<template>
	<view class="layout">
		<view class="navbar">
			<!-- 状态栏 -->
			<view class="statusBar" :style="{height:getStatusBarHeight() + 'px'}"></view>
			<!-- 标题栏 -->
			<view class="titleBar" :style="{height:getTitleBarHeight() + 'px',marginLeft:getLeftIcon()+'px'}">
				<slot name="back"></slot>
				<view class="tetle">{{title}}</view>
			</view>
		</view>

		<!-- 占位 -->
		<view class="fill" :style="{height:getNavBarHeight() + 'px'}">

		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		getStatusBarHeight,
		getTitleBarHeight,
		getNavBarHeight,
		getLeftIcon
	} from '@/utils/system.js'

	defineProps({
		title: {
			type: String,
			default: "壁纸"
		}
	})
</script>

<style lang="scss" scoped>
	.layout {
		.navbar {
			position: fixed; //固定定位
			top: 0;
			left: 0;
			width: 100%;
			z-index: 10; //提高层级

			background:
				linear-gradient(to bottom, transparent, #fff 400rpx), //从上往下 透明到白色 400rpx 指从400开始
				linear-gradient(to right, #baecec 20%, #F4E2D8);

			.statusBar {}

			.titleBar {
				display: flex; //默认显示一行
				align-items: center;
				padding: 0 30rpx;
				justify-content: space-between;

				/* 添加这个属性 */
				.back {
					margin-right: auto;
					/* 将 back 元素推到左边 */
				}

				.tetle {
					flex: 1;
					/* 让 title 元素占据中间空间 */
					text-align: center;
					/* 将 title 文本居中 */
				}
			}
		}

		.fill {}

	}
</style>